<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;

class DataCollection extends ResourceCollection
{
    private $status = '1';
    private $message = 'success';
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        if($request->type && $request->type<8){
            $data['items'][$request->type] = $this->collection;
        }else{
            $data = $this->collection;
        }
        return  $data;
    }

    public function with($request){
        //用户数据列表
        if($request->user_id){
            return  [
                'status' => $this->status,
                'message'   => $this->message,
                'userinfo' => new User(\App\User::find($request->user_id)),
            ];
        }else{
            return [
                'status' => $this->status,
                'message'   => $this->message,
            ];
        }
    }
}
